﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        private int r, g, b; //for red green and blue
        private int dr, dg, db;
        public Form1()
        {
            InitializeComponent();
            r = 45;
            g = 200;
            b = 65;
            dr = 15;
            dg = -7;
            db = 4;

        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.timer1.Enabled = !this.timer1.Enabled;
           
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            this.BackColor = Color.FromArgb(r, g, b);
            r = r + dr;
            if (r < 0) { r = (-1) * r; dr = (-1) * dr; }
            if (r > 255) { r = 255 - (r - 255); dr = (-1) * dr; }

            g = g - 7;
            if (g < 0) { g = (-1) * g; dg = (-1) * dg; }
            if (g > 255) { g = 255 - (g - 255); dg = (-1) * dg; }

            b = b + db;
            if (b < 0) { b = (-1) * b; db = (-1) * db; }
            if (b > 255) { b = 255 - (b - 255); db = (-1) * db; }
        }
    }
}
